package com.yingran.beiqi.activity.mapbox;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.plugins.china.maps.ChinaMapView;
import com.yingran.beiqi.Constants;
import com.yingran.beiqi.R;

/**
 * The most basic example of adding a government approved and performant China map to an activity.
 */
public class SimpleChinaMapViewActivity extends AppCompatActivity {
    private ChinaMapView mapView;
    private MapboxMap mapboxMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Mapbox access token is configured here. This needs to be called either in your application
        // object or in the same activity which contains the MapView. You will need a special Mapbox
        // China access token if you want to view any of our China examples and use China map styles.
        // Please fill out the form at https://www.mapbox.cn/contact to start the process of
        // receiving a special China access token. Thank you!
        Mapbox.getInstance(this, Constants.token);

        // This contains the MapView in XML and needs to be called after the access token is configured.
        setContentView(R.layout.activity_map_china);

        mapView = findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);
        mapView.getMapAsync(mapboxMap -> {
            this.mapboxMap = mapboxMap;

            // Customize map with markers, polylines, etc.


        });
    }

    // Add the mapView lifecycle to the activity's lifecycle methods
    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mapView.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mapView.onStop();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
}